package com.devfest.wishmaster.gui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.devfest.wishmaster.R;

public class WishListActivity extends Activity {
	
	ListView wishListView;
	WishListAdapter adapter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_wish_list);
		setTitle("Hello, Maria Lutsenko. Your wishlists");
		
//		TextView fullName = (TextView) findViewById(R.id.wish_list_fullname);
		wishListView = (ListView) findViewById(R.id.wish_list_listview);
		adapter = new WishListAdapter(this, MyApplication.getInstance().wishLists);
		wishListView.setAdapter(adapter);
		wishListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Intent intent = new Intent(WishListActivity.this, DetailActivity.class);
				intent.putExtra("position", position);
				startActivity(intent);
			}
		});
		String fName = "";
		if (!MyApplication.getInstance().userFullName.equals(""))
			fName = ", " + MyApplication.getInstance().userFullName;
//		fullName.setText("Hello" + fName);
//		ImageView checkImage = (ImageView) findViewById(R.id.wish_list_check_comment);
//		checkImage.setOnClickListener(new OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				try {
//					JSONParser.getInstance().checkComments();
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//				adapter = new WishListAdapter(WishListActivity.this, MyApplication.getInstance().wishLists);
//				wishListView.setAdapter(adapter);
//				wishListView.invalidate();
//			}
//		});
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.wish_list_menu, menu);
		return super.onCreateOptionsMenu(menu);
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
			switch (item.getItemId()) {
			case R.id.create_wish_list:
				createWishList();
				break;
			default:
				break;
			}
		return super.onOptionsItemSelected(item);
	}
	
	private void createWishList() {
		startActivity(new Intent(this, CreateWishListActivity.class));
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		MyApplication.getInstance().setActivity(this);
		adapter.notifyDataSetChanged();
	}
}